home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / SLAX 6.0.8 / slax-6.0.8.iso / slax / base / 006-devel.lzm / usr / include / kprocctrl.h < prev    next >
Encoding:
C/C++ Source or Header  |  2005-10-10  |  4.0 KB  |  151 lines

  1. /* This file is part of the KDE libraries
  2.     Copyright (C) 1997 Christian Czezakte (e9025461@student.tuwien.ac.at)
  3.  
  4.     This library is free software; you can redistribute it and/or
  5.     modify it under the terms of the GNU Library General Public
  6.     License as published by the Free Software Foundation; either
  7.     version 2 of the License, or (at your option) any later version.
  8.  
  9.     This library is distributed in the hope that it will be useful,
  10.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  11.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  12.     Library General Public License for more details.
  13.  
  14.     You should have received a copy of the GNU Library General Public License
  15.     along with this library; see the file COPYING.LIB.  If not, write to
  16.     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  17.     Boston, MA 02110-1301, USA.
  18. */
  19.  
  20. #ifndef __KPROCCTRL_H__
  21. #define __KPROCCTRL_H__
  22.  
  23. #include <qvaluelist.h>
  24.  
  25. #include "kprocess.h"
  26.  
  27. class QSocketNotifier;
  28.  
  29. /**
  30.  * @short Used internally by KProcess
  31.  * @internal
  32.  * @author Christian Czezatke <e9025461@student.tuwien.ac.at>
  33.  *
  34.  *  A class for internal use by KProcess only. -- Exactly one instance
  35.  *  of this class is created by KApplication.
  36.  *
  37.  * This class takes care of the actual (UN*X) signal handling.
  38.  */
  39. class KDECORE_EXPORT KProcessController : public QObject
  40. {
  41.   Q_OBJECT
  42.  
  43. public:
  44.   /**
  45.    * Create an instance if none exists yet.
  46.    * Called by KApplication::KApplication()
  47.    */
  48.   static void ref();
  49.  
  50.   /**
  51.    * Destroy the instance if one exists and it is not referenced any more.
  52.    * Called by KApplication::~KApplication()
  53.    */
  54.   static void deref();
  55.  
  56.   /**
  57.    * Only a single instance of this class is allowed at a time,
  58.    * and this static variable is used to track the one instance.
  59.    */
  60.   static KProcessController *theKProcessController; // kde4: rename: instance
  61.  
  62.   /**
  63.    * Automatically called upon SIGCHLD. Never call it directly.
  64.    * If your application (or some library it uses) redirects SIGCHLD,
  65.    * the new signal handler (and only it) should call the old handler
  66.    * returned by sigaction().
  67.    * @internal
  68.    */
  69.   static void theSigCHLDHandler(int signal); // KDE4: private
  70.  
  71.   /**
  72.    * Wait for any process to exit and handle their exit without
  73.    * starting an event loop.
  74.    * This function may cause KProcess to emit any of its signals.
  75.    *
  76.    * @param timeout the timeout in seconds. -1 means no timeout.
  77.    * @return true if a process exited, false
  78.    *         if no process exited within @p timeout seconds.
  79.    * @since 3.1
  80.    */
  81.   bool waitForProcessExit(int timeout);
  82.  
  83.   /**
  84.    * Call this function to defer processing of the data that became available
  85.    * on notifierFd().
  86.    * @since 3.2
  87.    */
  88.   void unscheduleCheck();
  89.  
  90.   /**
  91.    * This function @em must be called at some point after calling
  92.    * unscheduleCheck().
  93.    * @since 3.2
  94.    */
  95.   void rescheduleCheck();
  96.  
  97.   /*
  98.    * Obtain the file descriptor KProcessController uses to get notified
  99.    * about process exits. select() or poll() on it if you create a custom
  100.    * event loop that needs to act upon SIGCHLD.
  101.    * @return the file descriptor of the reading end of the notification pipe
  102.    * @since 3.2
  103.    */
  104.   int notifierFd() const;
  105.  
  106.   /**
  107.    * @internal
  108.    */
  109.   void addKProcess( KProcess* );
  110.   /**
  111.    * @internal
  112.    */
  113.   void removeKProcess( KProcess* );
  114.   /**
  115.    * @internal
  116.    */
  117.   void addProcess( int pid );
  118.  
  119. private slots:
  120.   void slotDoHousekeeping();
  121.  
  122. private:
  123.   friend class I_just_love_gcc;
  124.  
  125.   int fd[2];
  126.   bool needcheck;
  127.   QSocketNotifier *notifier;
  128.   QValueList<KProcess*> kProcessList;
  129.   QValueList<int> unixProcessList;
  130.  
  131.   static void setupHandlers();
  132.   static void resetHandlers();
  133.   static struct sigaction oldChildHandlerData;
  134.   static bool handlerSet;
  135.  
  136.   static int refCount;
  137.  
  138.   // Disallow instantiation
  139.   KProcessController();
  140.   ~KProcessController();
  141.  
  142.   // Disallow assignment and copy-construction
  143.   KProcessController( const KProcessController& );
  144.   KProcessController& operator= ( const KProcessController& );
  145. };
  146.  
  147.  
  148.  
  149. #endif
  150.  
  151.